package model.search;

import java.util.Iterator;
import java.util.TreeSet;

public class Keywords implements Iterable<String> {
	private static Stopwords stopwords = new Stopwords();

	private static RegReplace regReplace = new RegReplace();

	private TreeSet<String> keywords;

	public Keywords(String string) {
		
		if (string.length() == 0) {
			keywords = new TreeSet<String>();
			return;
		}
		string = string.toLowerCase();
		string = regReplace.manipulate(string);
		String[] words = string.split(" ");
		keywords = stopwords.manipulate(words);
	}

	public Keywords() {
		keywords = new TreeSet<String>();
	}

	public Iterator<String> iterator() {
		return keywords.iterator();
	}

	public String toString() {
		String text = new String();
		for (String item : keywords)
			text += item;

		int sum = 0;
		for (int i = 0; i < text.length(); i++)
			sum += text.charAt(i) * i;

		return Integer.toString(Math.abs(sum));
	}

	public String getPrintableString() {
		String text = new String();
		for (String item : keywords)
			text += ","+item;
		return text;
	}
	
	public boolean equals(Object object) {
		Keywords candidate = (Keywords) object;
		return candidate.toString().equals(this.toString());
	}
}
